Ext.define('PrjAPLean.view.paapply.PaApplyManagePanelViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.paapplymanagevc',
    
    onQueryClick: function(){
    	var conditionForm = this.getView().down('form');
    	var infoGrid = this.getView().down('grid');
    	var extraParams=conditionForm.getForm().getValues();
    	var gridStore = infoGrid.getStore('paapply');
    	gridStore.on("beforeload", function (gridStore, operation, eOpts) {
			 Ext.apply(gridStore.proxy.extraParams, extraParams);
			});
    	gridStore.loadPage(1,{"start":0,"limit":20});
    },
    onCreateClick: function(){
    	var component = this.getView().up('panel');
		var PaApplyPanel = Ext.create('PrjAPLean.view.paapply.PaApplyPanel');
		component.add(PaApplyPanel);
		component.setActiveTab(PaApplyPanel);
    },
    onRowClick:function(){
    	var selectModels = this.getView().down('grid').getSelectionModel().getSelection();
    	if(selectModels.length > 0){
    		var component = this.getView().up('panel');
			var PaApplyPanel = Ext.create('PrjAPLean.view.paapply.PaApplyPanel');
			component.add(PaApplyPanel);
			component.setActiveTab(PaApplyPanel);
    	} else {
    		Ext.Msg.alert('提示','请先选中一条记录。');
    	}
    },
    onDeleteClick: function(){
    	var selectModels = this.getView().down('grid').getSelectionModel().getSelection();
    	if(selectModels.length > 0){
    		if(selectModels[0].data.status == '12' || selectModels[0].data.status == '10'){
    		var id = selectModels[0].data.id;
        	var param = {id: id};
        	var gridStore = this.getViewModel().getStore('paapply');
    		Ext.Msg.confirm('提示','确认删除吗？',function(button){
    			if(button == "yes"){
    				masterDataContro.paapplyDelete(param, function(result){
    					if(result == 'success'){
    						Ext.Msg.alert('提示','删除成功。');
    		    			gridStore.reload();
    		    		}else{
    		    			Ext.Msg.alert('提示','操作失败。');
    		    		}
    		    	});
    			}
    		});
    		}else{
    			Ext.Msg.alert('提示','只有状态是[已创建]和[打回]的记录可以删除。');
    		}
    	}else{
    		Ext.Msg.alert('提示','请先选中一条记录。')
    	}
    }
});
